using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_Buyer_Message : Member, IRequiresSessionState
{
	private Shop_Message objShop_Message;
	protected GridView GridView1;
	protected Button DelMessage;
	protected ObjectDataSource ObjectDataSource1;
	protected Panel PnlGvList;
	protected Literal MessageTitle;
	protected Literal ltrSendName;
	protected TextBox txtContent;
	protected Label LbComtentError;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected CheckBox CheckBox1;
	protected Button ButdSend;
	protected PlaceHolder SendPanel;
	protected Literal Literal1;
	protected Literal LiSender;
	protected Literal ltrReadSenderName;
	protected Literal ltrReadContent;
	protected Button btnReply;
	protected PlaceHolder readPanel;
	protected Panel pnlRendMessage;
	public Shop_Message ObjShop_Message
	{
		get
		{
			if (this.objShop_Message == null)
			{
				this.objShop_Message = new Shop_Message(this.conn);
			}
			return this.objShop_Message;
		}
		set
		{
			this.objShop_Message = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ObjectDataSource1.SelectParameters["UserID"].DefaultValue = base.user.UserID.ToString();
		if (!base.IsPostBack)
		{
			this.PnlGvList.Visible = true;
			this.pnlRendMessage.Visible = false;
			if (Fetch.Get("action") == "read")
			{
				if (Fetch.GetID("MessageID") > 0)
				{
					int iD = Fetch.GetID("MessageID");
					DataTable messageByMessageID = this.ObjShop_Message.GetMessageByMessageID(iD);
					if (messageByMessageID.Rows.Count > 0)
					{
						this.ltrReadSenderName.Text = messageByMessageID.Rows[0]["M_SenderName"].ToString();
						this.ltrReadContent.Text = messageByMessageID.Rows[0]["M_Content"].ToString();
					}
					this.PnlGvList.Visible = false;
					this.pnlRendMessage.Visible = true;
					this.readPanel.Visible = true;
					this.SendPanel.Visible = false;
				}
			}
			if (Fetch.Get("action") == "send")
			{
				if (Fetch.GetID("MessageID") > 0)
				{
					int iD = Fetch.GetID("MessageID");
					this.BandMessage(iD);
					this.PnlGvList.Visible = false;
					this.pnlRendMessage.Visible = true;
					this.readPanel.Visible = false;
					this.SendPanel.Visible = true;
				}
			}
			this.GridView1.DataBind();
		}
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			bool flag = true;
			bool flag2 = true;
			Image image = (Image)e.Row.FindControl("QQImage");
			if (flag && image.ImageUrl != "")
			{
				image.ImageUrl = "http://wpa.qq.com/pa?p=1:" + image.ImageUrl + ":4";
			}
			else
			{
				image.Visible = false;
			}
			Image image2 = (Image)e.Row.FindControl("TaobaoImage");
			if (flag2 && image2.ImageUrl != "")
			{
				image2.ImageUrl = "http://amos1.taobao.com/online.ww?v=2&uid=" + base.Server.UrlEncode(image2.ImageUrl) + "&s=2";
				HyperLink hyperLink = (HyperLink)e.Row.FindControl("TaobaoLink");
				hyperLink.NavigateUrl = "http://amos1.taobao.com/msg.ww?v=2&Uid=" + base.Server.UrlEncode(hyperLink.NavigateUrl) + "&s=2";
			}
			else
			{
				image2.Visible = false;
			}
		}
	}
	protected void DelMessage_Click(object sender, EventArgs e)
	{
		ArrayList arrayList = new ArrayList();
		for (int i = 0; i < this.GridView1.Rows.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.GridView1.Rows[i].FindControl("MessageSelect");
			HiddenField hiddenField = (HiddenField)this.GridView1.Rows[i].FindControl("HiddenID");
			if (checkBox.Checked)
			{
				arrayList.Add(hiddenField.Value);
			}
		}
		for (int j = 0; j < arrayList.Count; j++)
		{
			int num = this.conn.Execute("delete HLShop_Message where M_ID=" + int.Parse(arrayList[j].ToString()));
		}
		this.GridView1.DataBind();
	}
	protected void ButdSend_Click(object sender, EventArgs e)
	{
		int num = 0;
		if (Fetch.GetID("MessageID") > 0)
		{
			num = Fetch.GetID("MessageID");
		}
		int num2 = 0;
		int num3 = 0;
		DataTable messageByMessageID = this.ObjShop_Message.GetMessageByMessageID(num);
		if (messageByMessageID.Rows.Count > 0)
		{
			string text = messageByMessageID.Rows[0]["M_SenderName"].ToString();
			if (messageByMessageID.Rows[0]["M_ProductID"] != DBNull.Value)
			{
				num2 = Convert.ToInt32(messageByMessageID.Rows[0]["M_ProductID"].ToString());
			}
			if (messageByMessageID.Rows[0]["M_UserID"] != DBNull.Value)
			{
				num3 = Convert.ToInt32(messageByMessageID.Rows[0]["M_UserID"].ToString());
			}
		}
		IDbDataParameter[] parameters = new IDbDataParameter[]
		{
			this.conn.CreateParameter("@M_ReplayID", DbType.String, num),
			this.conn.CreateParameter("@M_Type", DbType.Int32, 0),
			this.conn.CreateParameter("@M_ProductID", DbType.Int32, num2),
			this.conn.CreateParameter("@M_ShopID", DbType.Int32, 0),
			this.conn.CreateParameter("@M_DateTime", DbType.String, DateTime.Now.ToString()),
			this.conn.CreateParameter("@M_UserID", DbType.Int32, base.user.UserID),
			this.conn.CreateParameter("@M_Status", DbType.Boolean, 1),
			this.conn.CreateParameter("@M_Content", DbType.String, this.txtContent.Text),
			this.conn.CreateParameter("@M_ReceiverID", DbType.Int32, num3),
			this.conn.CreateParameter("@M_SenderName", DbType.String, base.user.UserName),
			this.conn.CreateParameter("@M_ReceiverName", DbType.String, this.ltrSendName.Text),
			this.conn.CreateParameter("@M_UserType", DbType.String, "saler")
		};
		string commandText = "INSERT INTO [HLShop_Message] ([M_ReplayID], [M_Type], [M_ProductID], [M_ShopID], [M_DateTime], [M_UserID], [M_Status], [M_Content], [M_ReceiverID], [M_SenderName], [M_ReceiverName], [M_UserType]) VALUES (@M_ReplayID, @M_Type, @M_ProductID, @M_ShopID,@M_DateTime , @M_UserID, @M_Status, @M_Content, @M_ReceiverID, @M_SenderName, @M_ReceiverName, @M_UserType)";
		int num4 = this.conn.Execute(commandText, parameters);
		if (num4 > 0)
		{
			string sql = "update HLShop_Message set M_Status=1 where M_ID=" + num;
			int num5 = this.conn.Execute(sql);
			if (num4 > 0 && num5 > 0)
			{
				this.WriteSuccessMsg("", "留言发送成功！", "Shop_Buyer_Message.aspx");
			}
			else
			{
				this.WriteErrMsg("", "留言发送失败", "");
			}
		}
	}
	protected void btnReply_Click(object sender, EventArgs e)
	{
		if (Fetch.GetID("MessageID") > 0)
		{
			int iD = Fetch.GetID("MessageID");
			base.Response.Redirect("Shop_Buyer_Message.aspx?action=send&MessageID=" + iD);
		}
	}
	private void BandMessage(int MsgID)
	{
		DataTable messageByMessageID = this.ObjShop_Message.GetMessageByMessageID(MsgID);
		if (messageByMessageID.Rows.Count == 1)
		{
			this.ltrSendName.Text = messageByMessageID.Rows[0]["M_SenderName"].ToString();
			this.txtContent.Text = string.Concat(new string[]
			{
				Environment.NewLine,
				Environment.NewLine,
				"------------------------------------------",
				Environment.NewLine,
				"在【",
				messageByMessageID.Rows[0]["M_SenderName"].ToString(),
				"】留言中提到：",
				Environment.NewLine,
				messageByMessageID.Rows[0]["M_Content"].ToString()
			});
		}
		else
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/NotData", new string[0]), "");
		}
	}
}
